<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/global/global-head.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>吉车惠后台管理系统</title>
    <%@include file="/global/global-other.jsp" %>

    <script type="text/javascript">
        var $sys_power_list = new Object();
        var $sys_power_list_Datagrid;
        var $menu;
        var $sys_power_list_toolbar = [
            {
                text:'<i class="fa fa-plus-square" aria-hidden="true"></i>添加',
                handler:function(){
                    $sys_power_list.saveInit();
                }
            },
            {
                text:'<i class="fa fa-edit" aria-hidden="true"></i>编辑',
                handler:function(){
                    $sys_power_list.updateInit();
                }
            },
            {
                text:'<i class="fa fa-trash-o" aria-hidden="true"></i>删除',
                handler:function(){
                    $sys_power_list.delete();
                }
            },'-',
            {
                text:'<i class="fa fa-undo" aria-hidden="true"></i>取消选择菜单',
                handler:function(){
                    $menu.tree('reload');
                    $("#filter_EQ_parent_power_id").val(0);
                    $sys_power_list_Datagrid.datagrid('load', {filter_EQ_parent_power_id: 0 });
                }
            }
        ];
        $(function(){
            //gird 初始化
            $sys_power_list_Datagrid = $('#sys_power_list_Datagrid').datagrid({
                filterBtnIconCls:'icon-filter',
                queryParams: {
                    filter_EQ_parent_power_id: 0,
                    filter_EQ_power_type: 1
                },
                pageSize : 20,
                remoteFilter:true
            });

            //初始化菜单
            $sys_power_list.menu();
        });

        //刷新
        $sys_power_list.reload = function(){
            //$("#filter_EQ_parent_power_id").val(0);
            //var queryParams = serializeObject($("#sys_power_list_form").serializeArray());
            //$('#sys_power_list_Datagrid').datagrid('options').queryParams = queryParams;
            //$('#sys_power_list_Datagrid').datagrid('reload');
            $("#sys_power_list_Datagrid").datagrid('reload');
        };

        var viewDialog = new Object();
        //添加
        $sys_power_list.saveInit = function(){
            viewDialog = parent.$.dialog({
                title: '<i class="fa fa-th-large"></i><span class="dialog-title">&nbsp;权限添加<span>',
                href: '${ctx}/sys/power/insert?_m=init&pid='+$("#filter_EQ_parent_power_id").val()+'&r='+Math.random(),
                width: 800,
                height: 440,
                modal: true,
                onClose : function() {
                    $(this).dialog('destroy');
                },
                buttons: [{
                    text:'<i class="fa fa-floppy-o" aria-hidden="true"></i>&nbsp;保 存',
                    width:'70px',
                    handler: function(){
                        viewDialog.find('iframe').get(0).contentWindow.submitForm(viewDialog, $sys_power_list_Datagrid,$menu,$sys_power_list);
                    }
                },{
                    text:'<i class="fa fa-reply" aria-hidden="true"></i>&nbsp;返 回',
                    width:'70px',
                    handler: function(){
                        viewDialog.dialog('destroy');
                    }
                }]
            });
        }

        //子页面赋值pid
        $sys_power_list.setPid = function(pid){
            $("#filter_EQ_parent_power_id").val(pid);
        }


        //编辑
        $sys_power_list.updateInit = function (){
            var row = $sys_power_list_Datagrid.datagrid('getSelected');
            if(row==null){
                $.messager.alert("提示",errMsg("请选择一行数据！"),"error");
            }else{
                viewDialog = parent.$.dialog({
                    title: '<i class="fa fa-th-large"></i><span class="dialog-title">&nbsp;权限编辑<span>',
                    href: '${ctx}/sys/power/update?_m=init&id='+row.powerId+'&r='+Math.random(),
                    width: 800,
                    height: 440,
                    modal: true,
                    onClose : function() {
                        $(this).dialog('destroy');
                    },
                    buttons:[{
                        text:'<i class="fa fa-floppy-o" aria-hidden="true"></i>保存',
                        width:'70px',
                        handler:function(){
                            viewDialog.find('iframe').get(0).contentWindow.submitForm(viewDialog, $sys_power_list_Datagrid,$menu);
                        }
                    },{
                        text:'<i class="fa fa-reply" aria-hidden="true"></i>返回',
                        width:'70px',
                        handler:function(){
                            viewDialog.dialog('destroy');
                        }
                    }]
                });
            }
        }

        //删除
        $sys_power_list.delete = function (){
            var row = $sys_power_list_Datagrid.datagrid('getSelected');
            if(row==null){
                parent.$.messager.alert("提示",errMsg("请选择一行数据！"),"error");
            }else{
                parent.$.messager.confirm('提示','是否要删除菜单名称【'+row.name+'】？',function(flag){
                    if (flag){
                        $.post('${ctx}/sys/power/delete?_m=exec', {id : row.powerId}, function(json) {
                            if(statusMsg(json)){
                                parent.$.messager.alert("提示","删除成功！","info",function(){
                                    $("#filter_EQ_parent_power_id").val(0);
                                    $sys_power_list_Datagrid.datagrid('load', {filter_EQ_parent_power_id: 0 });
                                    $sys_power_list_Datagrid.datagrid('reload');
                                    $menu.tree('reload');
                                });
                            }
                        }, "JSON");
                    }
                });
            }
        }

        //菜单树
        $sys_power_list.menu = function(){
            $menu = $('#menu_tree').tree({
                url: '${ctx}/sys/power/menus?r='+Math.random(),
                lines: true,
                onSelect:function(node){
                    pid = node.id;
                    var id = node.id;
                    $("#filter_EQ_parent_power_id").val(id);
                    //var queryParams = serializeObject($("#sys_power_list_form").serializeArray());
                    //$('#sys_power_list_Datagrid').datagrid('options').queryParams = queryParams;
                    //$("#sys_power_list_Datagrid").datagrid('reload');
                    $sys_power_list_Datagrid.datagrid('load', {filter_EQ_parent_power_id: id,filter_EQ_power_type: 1});
                },
                onLoadSuccess : function(node, data) {
                    $(this).tree("collapseAll");
                }
             });
        };

    </script>
</head>
<style type="text/css">
    .panel-tool{display:none}
    .panel-title{padding-left:40px;}
</style>
<body>
<form id="sys_power_list_form" name="sys_power_list_form">
<input  type="hidden" id="filter_EQ_parent_power_id" name="filter_EQ_parent_power_id" value=""/>
</form>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'west',split:false,border:true" title='<i class="fa fa-list-ul" style="color:#4fb2ff;"></i>&nbsp;&nbsp;<font color="#000000">系统菜单</font>' style="width:200px;">
        <div class="easyui-accordion" fit="false" border="false" >
            <ul id="menu_tree"></ul>
        </div>
    </div>
    <div data-options="region:'center',border:false">
        <table id="sys_power_list_Datagrid"  style="width:100%;height:100%"
               data-options="border:false,rownumbers:true,autoRowHeight:false,singleSelect:true,pagination:true,sortName:'seq',sortOrder:'asc',toolbar:$sys_power_list_toolbar,rowStyler: function(index,row){return {style:'height:30px'};},url:'${ctx}/sys/power/search?_m=load&filter_EQ_delete_status=0',method:'post'">
            <thead>
            <tr>
                <th data-options="field:'name',width:120,align:'center'">菜单名称</th>
                <th data-options="field:'url',width:300,align:'center'">相对地址</th>
                <th data-options="field:'useStatus',width:100,align:'center',formatter:
                    function(value,row,index){
                        if(row.useStatus=='1'){
                            return '使用';
                        }else if(row.useStatus=='2'){
                            return '<span style=\'color:red;\'>未使用</span>';
                        }
                    }
                ">使用状态</th>
                <th data-options="field:'icon',width:120,align:'center'">css icon</th>
                <th data-options="field:'seq',width:100,align:'center'">排序</th>
                <th data-options="field:'des',width:150,align:'center'">描述</th>
                <th data-options="field:'createAt',width:150,align:'center'">添加时间</th>
                <th data-options="field:'t',width:20,align:'center'"></th>
            </tr>
            </thead>
        </table>
    </div>
</div>
</body>
</html>